var page = -1;

$(function() {
	ajaxGetBlogArticle();
});

function ajaxGetBlogArticle() {
	page++;
	$.ajax({
		url : rootPath + "/blog/getBlogArticleByPage",
		type : "post",
		dataType : "json",
		data : {
			page : page
		},
		success : ajaxGetBlogArticle_back
	});
}

function ajaxGetBlogArticle_back(res) {
	if (res.result == JS_AJAX_SUCCESS) {
		$.each(res.badList, function() {
			var htmlStr = "";

			htmlStr += "<div class='index-left common-width-center-left'>";
			htmlStr += "<div class='info fleft'>";
			htmlStr += "<div class='image'>";
			htmlStr += "<img alt='' src='../resource/images/180/0.jpg'>";
			htmlStr += "</div>";

			var tags = this.blogTags.split(",");
			$.each(tags, function() {
				htmlStr += "<div class='label'>";
				htmlStr += "<div class='animate-bgcolor-fast'>" + this + "</div>";
				htmlStr += "</div>";
			});

			htmlStr += "</div>";
			htmlStr += "<div class='article fleft'>";
			htmlStr += "<div class='author fleft'>" + this.loginname + "</div>";
			htmlStr += "<div class='time fright'>" + this.blogCreateDttmStr + "</div>";
			htmlStr += "<div class='cboth'></div>";
			htmlStr += "<div class='title'>" + this.blogTitle + "</div>";
			htmlStr += "<div class='content'>";
			htmlStr += "<div class='image fleft'>";
			htmlStr += "<img alt='' src='../resource/images/test/1.jpg'>";
			htmlStr += "</div>";
			htmlStr += "<div class='text fleft'>" + this.blogContent + "</div>";
			htmlStr += "<div class='cboth'></div>";
			htmlStr += "</div>";
			htmlStr += "<div class='bottom fright'>";
			htmlStr += "<label><a href='" + rootPath + "/blog/article?article_id=" + this.blogId + "'>查看全文</a></label>";
			htmlStr += "<label>|</label>";
			htmlStr += "<label><a href='javascript: ajaxAddArticleFavourCnt(\"" + this.blogId + "\")'>喜欢</a>(<span id='span" + this.blogId + "'>" + this.blogFavourCnt + "</span>)</label>";
			htmlStr += "<label>访问(" + this.blogVisitCnt + ")</label>";
			htmlStr += "</div>";
			htmlStr += "<div class='cboth'></div>";
			htmlStr += "</div>";
			htmlStr += "<div class='cboth'></div>";
			htmlStr += "</div>";

			$("#blog-list").append(htmlStr);
		});
	} else {
		alert(res.msg);
	}
}

function ajaxAddArticleFavourCnt(article_id) {
	$.ajax({
		url : rootPath + "/blog/addBlogArticleFavourCnt",
		type : "post",
		dataType : "json",
		data : {
			article_id : article_id
		},
		success : ajaxAddArticleFavourCnt_back
	});
}

function ajaxAddArticleFavourCnt_back(res) {
	if (res.result == JS_AJAX_SUCCESS) {
		$('#span' + res.article_id).html(parseInt($('#span' + res.article_id).html()) + 1);
	}
}